package org.txlcn.demo.servicec;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.txlcn.demo.common.entity.Stock;

/**
 * Description:
 * Date: 2018/12/25
 *
 * @author ujued
 */
@Service
@Slf4j
public class StockServiceImpl {
    @Autowired
    private StockMapper stockMapper;

    @LcnTransaction
    @Transactional
    public String rpc(Integer number) {
        Stock oldStock = stockMapper.selectById("1");
        oldStock.setNumber(oldStock.getNumber() - number);
        stockMapper.updateById(oldStock);
        try {
            Thread.sleep(1000*20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
//        int i = 1 / 0;
        return "ok-service-c";
    }
}
